#include "stdafx.h"
#include "XButtonDraw.h"

#include <Util.h>



IMPLEMENT_SKIN_CLASS(CXButtonDrawImpl);



CXButtonDrawImpl::CXButtonDrawImpl()
{
    m_pImageDraw = NULL;
    Util::CreateObject(&m_pImageDraw);
}

CXButtonDrawImpl::~CXButtonDrawImpl()
{
    ;
}

//////////////////////////////////////////////////////////////////////////
// IXButtonDraw
HRESULT CXButtonDrawImpl::put_ImagePath(IN LPCTSTR szXNC)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->put_ImagePath(szXNC);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::put_Icon(IN LPCTSTR szXNC, BOOL bBig)
{
    return E_NOTIMPL;
}

HRESULT CXButtonDrawImpl::put_Icon(IN XICON xIcon, IN BOOL bDestroy)
{
    return E_NOTIMPL;
}

HRESULT CXButtonDrawImpl::get_ImagePath(OUT BSTR* pbstrXNC)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->get_ImagePath(pbstrXNC);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::put_Image(IN XIMAGE xImage)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->put_Image(xImage);
    return E_FAIL;
}

void CXButtonDrawImpl::put_DrawType(IN ImageDrawType type)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->put_DrawType(type);
}

HRESULT CXButtonDrawImpl::put_DrawParams(IN ImageDrawParams* pParam)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->put_DrawParams(pParam);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::get_DrawParams(OUT ImageDrawParams* pParam)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->get_DrawParams(pParam);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::get_ImageSize(OUT LPSIZE lpSize)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->get_ImageSize(lpSize);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::put_Index(IN INT nHIndex, IN INT nVIndex)
{
    if(m_pImageDraw != NULL)
    {
        int nHCount = 0, nVCount = 0;
        m_pImageDraw->get_SubCount(&nHCount, &nVCount);
        while(nHIndex > 0 && nHIndex >= nHCount)
        {
            -- nHIndex;
        }
        return m_pImageDraw->put_Index(nHIndex, nVIndex);
    }
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::get_Index(IN LPINT pnHIndex, IN LPINT pnVIndex)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->get_Index(pnHIndex, pnVIndex);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::put_SubCount(IN INT nHCount, IN INT nVCount)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->put_SubCount(nHCount, nVCount);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::get_SubCount(IN LPINT pnHCount, IN LPINT pnVCount)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->get_SubCount(pnHCount, pnVCount);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::IsImageValid(OUT LPBOOL pbValid)
{
    if(m_pImageDraw != NULL)
    {
        *pbValid = m_pImageDraw->IsDrawValid();
        return S_OK;
    }
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::put_AlphaMode(IN eImageAlphaMode nAlphaMode)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->put_AlphaMode(nAlphaMode);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::get_AlphaMode(OUT eImageAlphaMode* pnAlphaMode)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->get_AlphaMode(pnAlphaMode);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::put_AlphaValue(IN BYTE byAlphaValue)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->put_AlphaValue(byAlphaValue);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::get_AlphaValue(OUT LPBYTE pbyAlphaValue)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->get_AlphaValue(pbyAlphaValue);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::put_TransparentColor(IN COLORREF clrTrans)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->put_TransparentColor(clrTrans);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::get_TransparentColor(OUT LPCOLORREF pclrTrans)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->get_TransparentColor(pclrTrans);
    return E_FAIL;
}

HANDLE CXButtonDrawImpl::GetDrawBuffer(IN SIZE* pSize)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->GetDrawBuffer(pSize);
    return NULL;
}

void CXButtonDrawImpl::ReleaseDrawBuffer(IN HANDLE hBuffer)
{
    if(m_pImageDraw != NULL)
        m_pImageDraw->ReleaseDrawBuffer(hBuffer);
}

HRESULT CXButtonDrawImpl::DrawBuffer(IN XCANVAS xCanvas, IN HANDLE hBuffer, IN const RECT* lpDes)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->DrawBuffer(xCanvas, hBuffer, lpDes);
    return E_FAIL;
}

//////////////////////////////////////////////////////////////////////////
// IXDraw
HRESULT CXButtonDrawImpl::Draw(IN XCANVAS xCanvas, const RECT* lpDes)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->Draw(xCanvas, lpDes);
    return E_FAIL;
}

HRESULT CXButtonDrawImpl::Draw(IN XCANVAS xCanvas, IN const RECT* lpSrc, IN const RECT* lpDes)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->Draw(xCanvas, lpSrc, lpDes);
    return E_FAIL;
}

BOOL CXButtonDrawImpl::IsDrawValid()
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->IsDrawValid();
    return E_FAIL;
}

void CXButtonDrawImpl::EnableColorize(IN BOOL bEnable)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->EnableColorize(bEnable);
}

void CXButtonDrawImpl::Colorize(IN int hue, IN int sat, IN int light)
{
    if(m_pImageDraw != NULL)
        return m_pImageDraw->Colorize(hue, sat, light);
}

//////////////////////////////////////////////////////////////////////////
// IBaseObj
void CXButtonDrawImpl::OnFinalRelease()
{
    ReleaseData();
}

//////////////////////////////////////////////////////////////////////////
// CXButtonDrawImpl
void CXButtonDrawImpl::ReleaseData()
{
    XSAFE_RELEASE(m_pImageDraw);
}